# Copyright 2009 http://www.yuntien.com
# Licensed under the Apache License, Version 2.0

from google.appengine.api import users
from google.appengine.api import memcache
from ytblog.model import cache

def check_page_cache(method):
  def new_method(self, *args, **kwds):
    #only use cache for anonymous user
    if users.get_current_user():
      method(self, *args, **kwds)
      return
        
    key = cache.PAGE + '_' + self.request.path_qs
    data = memcache.get(key)
    if data is not None:
      self.response.out.write(data)
    else:
      method(self, *args, **kwds)
      memcache.add(key, self.response.out.getvalue())
            
  return new_method
